#pragma once

#include "Expression.h"

#include "ValueSpecification.h"

namespace uml {

const QString Expression::symbol_default_ = "";
Expression::Expression(const QString& umlType)
    : ValueSpecification(umlType) {}

void Expression::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ValueSpecification::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(operands_, "operands", json, errorList);
    symbol_ = json.value("symbol").toString(symbol_default_);
}

void Expression::toJson(QJsonObject& json) {
    ValueSpecification::toJson(json);
    JsonSerializable::toJsonArray(operands_, "operands", json);
    if (symbol_ != symbol_default_) {
        json.insert("symbol", symbol_);
    }
}

/// <summary>
/// operands getter
/// Specifies a sequence of operand ValueSpecifications.
/// </summary>
vector<shared_ptr<ValueSpecification>>& Expression::operands() {
    return operands_;
}

/// <summary>
/// symbol getter
/// The symbol associated with this node in the expression tree.
/// </summary>
QString Expression::symbol() const {
    return symbol_;
}

/// <summary>
/// symbol setter
/// The symbol associated with this node in the expression tree.
/// </summary>
void Expression::setSymbol(const QString& value) {
    symbol_ = value;
}

} // namespace uml
